<?php
class Add extends Controller {
	public function html() {
		$mUser = new User_model();
		$currUser = $mUser->currUser();
		if(!$currUser) header('Location:/auth/login?backurl='.urlencode('/yunying/product/category/add'));
		
		$data = array();
		$tpl = 'yunying/product/category/info.html';
		
		$this->display($data, $tpl);
	}
	public function json() {
		$name = $this->post('name', 'str');
		
		if(!$name) $this->displayJSON(array('status' => -1, 'message' => '请输入分类名称'));
		$mProduct = new Product_model();
		
		//检查分类是否存在
		$params = array('name' => $name);
		$result = $mProduct->categoryInfo($params);
		if($result) $this->displayJSON(array('status' => -2, 'message' => '分类名称已存在'));
		
		$result = $mProduct->categoryCreate($params);
		if($result) $this->displayJSON(array('status' => 0, 'message' => '添加分类成功'));
		else $this->displayJSON(array('status' => -3, 'message' => '添加分类失败'));
	}
}